// @Author YaoYa
// @Date 2024-07-29 22:17:00
// @Desc
package main

import (
	"go.uber.org/zap"
	"time"
)

func main() {
	logger, _ := zap.NewProduction() //基于生产环境
	//logger, _ := zap.Development() //基于开发环境
	defer logger.Sync() // flushes buffer, if any
	url := "https://imooc.com"
	//方式一。sugar
	sugar := logger.Sugar()
	sugar.Infow("failed to fetch URL",
		// Structured context as loosely typed key-value pairs.
		"url", url,
		"attempt", 3,
		"backoff", time.Second,
	)
	sugar.Infof("Failed to fetch URL: %s", url)

	//方式二、直接使用logger
	logger.Info("failed to fetch URL",
		zap.String("url", url),
		zap.Int("nums", 3))

	//区别 方式二性能快一些、方式一方便

}
